﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ShredTheLog.Common.MVVM;

namespace ShredTheLog.Controls
{
    public class BrushPicker : ControlBase
    {
        static BrushPicker()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(BrushPicker), new FrameworkPropertyMetadata(typeof(BrushPicker)));
        }

        public BrushPicker()
        {
            BrowseCommand = new DelegateCommand(
                () =>
                {
                    var dlg = new System.Windows.Forms.ColorDialog() 
                    {
                        Color = Value != null ? System.Drawing.Color.FromArgb(Value.Color.A, Value.Color.R, Value.Color.G, Value.Color.B) : System.Drawing.Color.White
                    };
                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        Value = new SolidColorBrush(Color.FromArgb((byte)dlg.Color.A, (byte)dlg.Color.R, (byte)dlg.Color.G, (byte)dlg.Color.B));
                }, () => !IsReadOnly);
        }

        public SolidColorBrush Value
        {
            get { return (SolidColorBrush)GetValue(ValueProperty); }
            set { SetValue(ValueProperty, value); }
        }
        public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(SolidColorBrush), typeof(BrushPicker));

        public ICommand BrowseCommand
        {
            get { return (ICommand)GetValue(BrowseCommandProperty); }
            set { SetValue(BrowseCommandProperty, value); }
        }
        public static readonly DependencyProperty BrowseCommandProperty = DependencyProperty.Register("BrowseCommand", typeof(ICommand), typeof(BrushPicker));
    }
}
